<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	<h4 class="modal-title">常用菜单</h4>
</div>
<div class="modal-body">
	<div class="list-group" style="text-align: center;">
		<table width="80%" id="menuTable">

			{% for firstMenu in firstMenus %}

			<tr>
				<td width="20%" align="left"><strong>{{firstMenu.name}}</strong></td>
				<td width="80%" align="left">

				</td>
			</tr>

			{% if secondMenus[firstMenu.id] %} {% for secondMenu in secondMenus[firstMenu.id] %}

			<tr>
				<td width="20%" align="left" style="padding-left: 20px;">{{ secondMenu.name }}</td>
				<td width="80%" align="left">
					{% if secondMenus[secondMenu.id] %} 
					{% for thirdMenu in secondMenus[secondMenu.id] %}
					<input type="checkbox" value="{{thirdMenu.id}}" onclick="chk()" {{'checked' if customMenus.indexOf(''+thirdMenu.id)>-1 else '' }}/>{{thirdMenu.name}} {% endfor %} {% endif %}
				</td>
			</tr>
			{% endfor %} 
			{% endif %} 
			{% endfor %}
		</table>
	</div>
</div>
<div class="modal-footer">
	<button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
	<button type="button" id="okCustom" class="btn btn-primary">确 认</button>
</div>
<script type="text/javascript">
	function chk() {
		var ids = [];
		$("#menuTable").find("input[type=checkbox]").each(function() {
			if($(this).prop("checked")) {
				ids.push($(this).val());
			}
		});
		if(ids.length > 5) {
			Toast.error("最多可选择5个菜单");
			return ids;
		}
		return ids;
	}
	$(function() {
		$("#okCustom").on("click", function() {
			var ids = chk();
			if(ids.length < 6) {
				$.post("/system/user/custom", {
					ids: JSON.stringify(ids)
				}, function(data) {
					if(data.errno == 0) {
						$('#homeDetail').modal('hide');
						Toast.success(data.data);
					} else {
						Toast.error(data.errmsg);
					}
				}, "json");
			}
		});
	});
</script>